package gold.vo;

/**
 * Created by fanzhenyu02 on 2020/3/14.
 */

import gold.utils.InputUtil;

/**
 * Definition for singly-linked list.
 */
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public static ListNode createList(String list) {
        String[] nodeList = list.split("->");
        ListNode start = new ListNode(Integer.parseInt(nodeList[0].trim()));
        ListNode curNode = start;
        for (int i = 1; i < nodeList.length; i++) {
            curNode.next = new ListNode(Integer.parseInt(nodeList[i].trim()));
            curNode = curNode.next;
        }

        return start;
    }

    public static ListNode createListFromArrayString(String input) {
        int[] valArray = InputUtil.toIntegerArray(input);
        ListNode start = new ListNode(valArray[0]);
        ListNode curNode = start;
        for (int i = 1; i < valArray.length; i++) {
            curNode.next = new ListNode(valArray[i]);
            curNode = curNode.next;
        }

        return start;
    }

    public static void main(String[] args) {
        System.out.println(createList("1->1->2->3->3"));
    }

}
